Socket
Socket
Sign inDemoInstall

h3

Package Overview
Dependencies
14
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    h3

Minimal H(TTP) framework built for high performance and portability.


Version published
Maintainers
1
Created

Package description

What is h3?

The h3 npm package is a high-performance HTTP framework for Node.js, designed to be lightweight and fast. It is often used for building APIs and microservices, providing a simple and efficient way to handle HTTP requests and responses.

What are h3's main functionalities?

Basic HTTP Server

This code demonstrates how to create a basic HTTP server using the h3 package. The server listens on port 3000 and responds with 'Hello, world!' to any incoming requests.

const { createApp } = require('h3');
const { createServer } = require('http');

const app = createApp();

app.use('/', (req, res) => {
  res.end('Hello, world!');
});

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Middleware Support

This example shows how to use middleware with the h3 package. The middleware logs each incoming request's method and URL before passing control to the next handler.

const { createApp } = require('h3');
const { createServer } = require('http');

const app = createApp();

// Middleware to log requests
app.use((req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
});

app.use('/', (req, res) => {
  res.end('Hello, world!');
});

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Routing

This code demonstrates how to set up routing with the h3 package. It defines GET and POST routes for the '/hello' path, responding with different messages based on the HTTP method.

const { createApp, useRouter } = require('h3');
const { createServer } = require('http');

const app = createApp();
const router = useRouter();

router.get('/hello', (req, res) => {
  res.end('Hello, GET!');
});

router.post('/hello', (req, res) => {
  res.end('Hello, POST!');
});

app.use(router);

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Other packages similar to h3

Changelog

Source

v1.12.0

compare changes

🚀 Enhancements

  • Improve typed headers (#625)
  • Export event-stream types (112fa33)

🩹 Fixes

  • getRequestUrl: Forward opts to getRequestProtocol (#776)
  • readRawBody: Read chunked body (#652)
  • proxy: Better error when upstream proxy fails (#746)
  • node: Make sure onBeforeResponse and onAfterResponse are called with error code (#756)
  • sse: Prevent onClosed from firing twice in EventStream (#704)
  • plain: Avoid import from unenv internals (#781)

💅 Refactors

  • session: Remove unnecessary async for clear (#729)
  • Update unenv import (76736ea)

📖 Documentation

  • Fix typo (#699)
  • Fix typo (#707)
  • Fix typo (#712)
  • Fix typo (#730)
  • Fix typo (#732)
  • Remove extra space (#718)
  • Add semi (#710)
  • event-handler: Fix typo (#684)
  • Add jsdoc examples for response utils (#677)
  • Add note for getRequestIP return value (#726)
  • Fix session example (#702)
  • Add jsdoc examples for request utils (#680)
  • Fix typo (#734)
  • Correct zod validation example (#735)
  • Fix typos (#738)
  • Fix typo (#758)
  • Add usage example for handleCors (#747)
  • Fix typo for text/html content-type (#764)
  • Update mogen example to use combined log format (#771)
  • Fix typo for plain adapter example (#766)
  • examples: Add cors example (#700)
  • Fix respondWith event object (#775)
  • Provide async for request body (#777)
  • error-handling: Add string vs object errors and update createError jsdoc (#762)

🏡 Chore

🤖 CI

  • Remove node 16 from test matrix (458cfac)

❤️ Contributors

Readme

Source

H3

npm version npm downloads

H3 (pronounced as /eɪtʃθriː/, like h-3) is a minimal h(ttp) framework built for high performance and portability.

[!NOTE] You are on the v1 branch. Check out h3 main for latest.

👉 Documentation

Contribution

Local development
  • Clone this repository
  • Install the latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run tests using pnpm dev or pnpm test

License

Published under the MIT license. Made by @pi0 and community 💛


🤖 auto updated with automd

FAQs

Last updated on 20 Jun 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc